package com.ruoyi.traces.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.traces.domain.TraceSettings;
import com.ruoyi.traces.service.ITraceSettingsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 溯源界面配置Controller
 * 
 * @author ruoyi
 * @date 2023-03-30
 */
@RestController
@RequestMapping("/trace/settings")
public class TraceSettingsController extends BaseController
{
    @Autowired
    private ITraceSettingsService traceSettingsService;

    /**
     * 查询溯源界面配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:settings:list')")
    @GetMapping("/list")
    public TableDataInfo list(TraceSettings traceSettings)
    {
        startPage();
        List<TraceSettings> list = traceSettingsService.selectTraceSettingsList(traceSettings);
        return getDataTable(list);
    }

    /**
     * 导出溯源界面配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:settings:export')")
    @Log(title = "溯源界面配置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TraceSettings traceSettings)
    {
        List<TraceSettings> list = traceSettingsService.selectTraceSettingsList(traceSettings);
        ExcelUtil<TraceSettings> util = new ExcelUtil<TraceSettings>(TraceSettings.class);
        return util.exportExcel(list, "settings");
    }

    /**
     * 获取溯源界面配置详细信息
     */
    @GetMapping("/information")
    public AjaxResult getInfo()
    {
        return AjaxResult.success(traceSettingsService.selectTraceSettingsById());
    }

    /**
     * 新增溯源界面配置
     */
    @PreAuthorize("@ss.hasPermi('system:settings:add')")
    @Log(title = "溯源界面配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TraceSettings traceSettings)
    {
        return toAjax(traceSettingsService.insertTraceSettings(traceSettings));
    }

    /**
     * 修改溯源界面配置
     */
    @PreAuthorize("@ss.hasPermi('system:settings:edit')")
    @Log(title = "溯源界面配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TraceSettings traceSettings)
    {
        return toAjax(traceSettingsService.updateTraceSettings(traceSettings));
    }

    /**
     * 删除溯源界面配置
     */
    @PreAuthorize("@ss.hasPermi('system:settings:remove')")
    @Log(title = "溯源界面配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(traceSettingsService.deleteTraceSettingsByIds(ids));
    }
}
